package cn.com.sparknet.jsindustrymanager.provider;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public final class SPManager
{

    public static final String SP_NAME                       = "SPManager";

    public static final String SP_KEY_REDISTERED_SERVERADDR  = "REDISTERED_SERVERADDR";
    public static final String SP_KEY_REDISTERED_IMEI        = "REDISTERED_IMEI";
    public static final String SP_KEY_REDISTERED_DEVICEID    = "REDISTERED_DEVICEID";
    public static final String SP_KEY_REDISTERED_PHONENUMBER = "REDISTERED_PHONENUMBER";
    public static final String SP_KEY_REDISTERED_IMSI        = "REDISTERED_IMSI";

    private SPManager()
    {
    }

    public static String[] getRedisteredInfo(Context context)
    {
        SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        String serverAddr = sp.getString(SP_KEY_REDISTERED_SERVERADDR, null);
        String imei = sp.getString(SP_KEY_REDISTERED_IMEI, null);
        String deviceId = sp.getString(SP_KEY_REDISTERED_DEVICEID, null);
        String phoneNumber = sp.getString(SP_KEY_REDISTERED_PHONENUMBER, null);
        String imsi = sp.getString(SP_KEY_REDISTERED_IMSI, null);
        if (serverAddr == null || imei == null || deviceId == null || phoneNumber == null || imsi == null)
            return null;
        return new String[] { serverAddr, imei, deviceId, phoneNumber, imsi };
    }

    public static void setRedisteredInfo(Context context, String[] info)
    {
        SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString(SP_KEY_REDISTERED_SERVERADDR, info[0]);
        editor.putString(SP_KEY_REDISTERED_IMEI, info[1]);
        editor.putString(SP_KEY_REDISTERED_DEVICEID, info[2]);
        editor.putString(SP_KEY_REDISTERED_PHONENUMBER, info[3]);
        editor.putString(SP_KEY_REDISTERED_IMSI, info[4]);
        editor.commit();
    }

}
